package org.wizehack.mri.code;

import java.io.File;
import java.util.ArrayList;

class FileListReader {
	private static ArrayList<String> fileList = null;
	
	FileListReader(){
		fileList = new ArrayList<String>();
	}
	
	public ArrayList<String> readFiles(File file) {
		
		if (file == null || !file.exists()) {
			return null;
		}

		if (file.isDirectory()) {
			String[] files = file.list();
			
			if (files != null) {
				for (int i = 0; i < files.length; i++) {
					readFiles(new File(file, files[i]));
				}
			}
			
		} else {
			try {
				String name = file.getName().toLowerCase();
				if(name.endsWith(".java")) {
					String fileCanonicalPath = file.getCanonicalPath();
					fileList.add(fileCanonicalPath);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		return fileList;
	}
	
//	public static void main(String[] args) {
//		FileListReader fileListReader = new FileListReader();
//		ArrayList<String> fList = new ArrayList<String>();
//		String path = "C:/Users/Gold_Youn/Desktop/LGProject/dev/TestProject";
//		
//		fList = fileListReader.readFiles(new File(path));
//				
//		for(int i=0; i<fList.size(); i++){
//			System.out.println(fList.get(i));
//		}
//	}
}
